package com.quotes.datamodell;

import java.util.*;

import org.apache.poi.hssf.usermodel.HSSFDateUtil;

public class DataRow 
{
	private List<Object> cells;
	
	public DataRow() {
		cells = new ArrayList<Object>();
	}
	
	public DataRow(Object... values) {
		this();
		
		for (Object o : values) {
			addCell(o);
		}
	}
	
	public void addCell(Object value) {
		cells.add(value);
	}
	
	public void addCells(Object[] values) {
		for (Object o : values) {
			addCell(o);
		}
	}
	
	public int getNumberOfCells() {
		return cells.size();
	}
	
	public Object getValue(int columnIndex) {
		return cells.get(columnIndex);
	}
	
	public List<Object> getCells() {
		return cells;
	}
	
	public String toString() {
		String result = "";
		
		for (Object o : cells) {
			result += o.toString() + " | ";
		}
		
		return result;
	}
	
	public void convertFromExcelDate(int colIndex) {
		Double value = (Double)cells.get(colIndex);
		cells.set(colIndex, HSSFDateUtil.getJavaDate(value));
	}
	
	public double getDoubleValue(int columnIndex) {
		try {
			return (Double)cells.get(columnIndex);
		} catch (Exception e) {
			return 0;
		}
	}
	
	public Date getDateValue(int columnIndex) {
		return (Date)cells.get(columnIndex);
	}
}
